package MoC;

import java.util.*;

import db.*;
import sdf.*;

//////////////////////////////////////////////////////////////////////////
//// ClassResult
/**

    Vai armazenando as informacoes da analise, indicando a resposta
    para cada modelo. Essa classe contempla tanto atores Atomicos
    
    Isso aqui devia ser uma classe base , pois o compositeactorResult eh
    quase igual. So tem o valid as atomic a mais....

@author Ivan Jeukens
@version v 0.1 22/10/2002
*/
public class ClassResult {

    public ClassResult(ClassInfo info) {
        _info = info;

        _validFor = new LinkedList();
        _toVerify = new LinkedList();

        _portSampleRates = new HashMap();
    }

    ///////////////////////////////////////////////////////////////////
    ////                        public methods                     ////

    public void setUseTime() {
        _useTime = true;
    }
    
    public boolean isTimed() {
        return _useTime;
    }
    
    public boolean hasError() {
        return _hasError;
    }

    public void setHasError(boolean value) {
        _hasError = value;
    }

    public String getName() {
        return _info.getName();
    }

    public dbInfo getInfo() {
        return _info;
    }

    // Identifica se o ator foi escrito (ou contem um director) especificamente 
    // para um modelo
    public boolean isSpecific() {
        return _isSpecific;
    }

    // Se for o caso, o nome do modelo
    public String getSpecificMoC() {
        return _specificMoC;
    }

    public void setSpecificMoC(String name) {
        _specificMoC = name;
        _isSpecific = true;
    }

    public boolean isValidFor(String MoC) {
        return _validFor.contains(MoC);
    }

    public void setValidFor(String moc) {
        if(!_validFor.contains(moc)) {
            _validFor.add(moc);
        }

        if(_toVerify.contains(moc)) {
            _toVerify.remove(moc);
        }
    }

    public Iterator validForIterator() {
        return _validFor.iterator();
    }

    public void addToVerify(String MoC) {
        _toVerify.add(MoC);
    }

    public Iterator toVerifyIterator() {
        return _toVerify.iterator();
    }

    public boolean toVerify(String moc) {
        return _toVerify.contains(moc);
    }
    
    public void removeToVerify(String moc) {
        if(_toVerify.contains(moc)) {
            _toVerify.remove(moc);
        }
    }

    public void setPortsSampleRates(HashMap sr) {
        _portSampleRates = sr;
    }
    
    public PortSampleRate getPortSampleRate(String name) {
        return (PortSampleRate) _portSampleRates.get(name);
    }

    
    public Iterator portsSampleRatesIterator() {
        return _portSampleRates.values().iterator();
    }
    
    public void setSRPortsSampleRates(HashMap sr) {
        _SRportSampleRates = sr;
    }

    public PortSampleRate getSRPortSampleRate(String portname) {
        return (PortSampleRate) _SRportSampleRates.get(portname);
    }
    
    public Iterator SRportsSampleRatesIterator() {
        return _SRportSampleRates.values().iterator();
    }
    
    public void setSROutputDependency(HashMap map) {
        _SROutputDependency = map;
    }
    
    public HashMap getSROutputDependency() {
        return _SROutputDependency;
    }

    public String toString() {
        StringBuffer ret = new StringBuffer("ClassResult for " + 
            _info.getName() + "\n");

        ret.append("isSpecific? " + _isSpecific + "\n");
        if(_isSpecific) {
            ret.append("  SpecificMoC = " + _specificMoC + "\n");
        }

        ret.append("Valid For: ");
        for(int i = 0;i < _validFor.size();i++) {
            String s = (String) _validFor.get(i);
            ret.append(s + " ");
        }
        ret.append("\n");

        ret.append("To Verify: ");
        for(int i = 0;i < _toVerify.size();i++) {
            String s = (String) _toVerify.get(i);
            ret.append(s + " ");
        }
        ret.append("\n");

        return ret.toString();
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private variables                  ////

    private ClassInfo _info;

    private boolean _isSpecific;
    private String _specificMoC;

    private LinkedList _validFor;
    private LinkedList _toVerify;

    private boolean _hasError;
    
    private boolean _useTime;

    private HashMap _portSampleRates;
    private HashMap _SROutputDependency;
    private HashMap _SRportSampleRates;
}
